package com.lzm.ydpt.mvp.presenterimpl;

import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.basemvp.basebean.BaseResponseBean;
import com.byt.framlib.basemvp.boby.FormBodys;
import com.byt.framlib.basemvp.exception.ApiException;
import com.byt.framlib.basemvp.listener.OnLoadingErrorListener;
import com.byt.framlib.basemvp.listener.OnLoadingProgressListener;
import com.lzm.ydpt.module.order.activity.AddAddressBookActivity;
import com.lzm.ydpt.mvp.api.ProgressSubscriber;
import com.lzm.ydpt.mvp.contract.AddAddressBookContract;
import com.lzm.ydpt.mvp.modelimpl.AddAddressBookModelImpl;

/**
 * 类名称：AddAddressBookPresenterImpl
 * 类描述：代理实现
 */
public class AddAddressBookPresenterImpl extends BasePresenter implements AddAddressBookContract.Presenter {

    private AddAddressBookContract.View mView;
    private AddAddressBookContract.Model mModel;

    public AddAddressBookPresenterImpl(AddAddressBookActivity context) {
        super(context);
        this.mView = context;
        this.mModel = new AddAddressBookModelImpl();
    }

    @Override
    public void onAddAddressBook(FormBodys formBodys) {
        mManager.http(mModel.onAddAddressBook(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<Object>() {
            @Override
            public void onLoadingResult(BaseResponseBean<Object> entity) {
                mView.onAddAddressBook(entity.getMessage());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onAddAddressBook"));
    }
}